package com.cgsd.heyu.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.android.library.adapter.BaseMultiItemAdapter;
import com.android.library.adapter.ClickTypeListener;
import com.android.library.adapter.ViewHolder;
import com.cgsd.heyu.R;
import com.cgsd.heyu.entity.TaskEntity;
import com.cgsd.heyu.ui.home.fragment.TaskAdFragment;

import java.util.List;

/**
 * @author xiaoxing
 * Description 说明
 * CreateData: 2020/11/4
 */
public class TaskAdapter extends BaseMultiItemAdapter<TaskEntity> {
    public ClickTypeListener clickTypeListener;

    public void setClickTypeListener(ClickTypeListener clickTypeListener) {
        this.clickTypeListener = clickTypeListener;
    }

    public TaskAdapter(Context mContext, List<TaskEntity> mDatas) {
        super(mContext, mDatas);
    }

    @Override
    protected int muItemViewType(int position, TaskEntity taskEntity) {
        return 0;
    }

    @Override
    protected int muLayoutId(int itemType) {
        return R.layout.item_task;
    }

    @Override
    public void convert(ViewHolder holder, TaskEntity taskEntity, int position) {
        View view = holder.getView(R.id.view_line);
        TextView tvConfirm = holder.getView(R.id.tv_confirm);
        ImageView ivBg = holder.getView(R.id.image);

        holder.setText(R.id.tv_title,taskEntity.taskTitle);
        holder.setText(R.id.tv_des,"可做"+taskEntity.taskNum + "次  "+
                taskEntity.userTaskClickCount + "/" + taskEntity.taskNum);
        if (position == mDatas.size() - 1){
            view.setVisibility(View.INVISIBLE);
        }else {
            view.setVisibility(View.VISIBLE);
        }
        if (TaskEntity.COMPLETE.equals(taskEntity.userTaskClickStatus)){
            tvConfirm.setTextColor(Color.parseColor("#999999"));
            tvConfirm.setText(mContext.getString(R.string.completed));
            tvConfirm.setBackgroundResource(R.drawable.border_max_gray);
        }else {
            tvConfirm.setTextColor(ContextCompat.getColor(mContext,R.color.app_color));
            tvConfirm.setText(mContext.getString(R.string.get_it_now));
            tvConfirm.setBackgroundResource(R.drawable.border_max_blue);
        }

        switch (taskEntity.taskType){
            case TaskEntity.REWARD_VIDEO:
                ivBg.setImageResource(R.mipmap.task_reward_vido);
                break;
            case TaskEntity.FULL_VIDEO:
                ivBg.setImageResource(R.mipmap.task_full_video);
                break;
            case TaskEntity.SPLASH:
                ivBg.setImageResource(R.mipmap.task_max_iamge);
                break;
            case TaskEntity.UNIFIED_INTERSTITIAL:
                ivBg.setImageResource(R.mipmap.task_min_iamge);
                break;
            case TaskEntity.WEB_AD:
            case TaskEntity.LOOK_NEWS:
            case TaskEntity.XW_GAME:
                ivBg.setImageResource(R.mipmap.task_min_iamge);
                holder.setText(R.id.tv_title,""+taskEntity.taskTitle);
                holder.setText(R.id.tv_des,""+taskEntity.remark);
                break;

            default:
        }

        tvConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (clickTypeListener != null){
                    clickTypeListener.clickTypePosition(v, TaskAdFragment.CLICK_TASK_BTN,position);
                }
            }
        });
    }
}
